package Bench::Test::Base;

use 5.008004;
use strict;
use warnings;

use Cwd;
use File::Basename;

our $VERSION = '0.01';

sub error_no_param {
   my $param = shift;
   die "You must set " . $param . " parameter in " . __PACKAGE__ . " constructor\n";
}

#============================================================================== 
# Object Constructor.
# - Inputs:  Classname and parameter hash including:
#
#    * WORKDIR: Path to saved base files
#
# - Outputs: The blessed reference
#============================================================================== 
sub new {
   my ($class, %params) = @_;

   my $workdir = $params{WORKDIR} or error_no_param("WORKDIR");
  
   return bless {
      WORKDIR    => $workdir,
      CURRENTDIR => cwd, 
   }, $class;
}

sub get_result {
   my ($self, $params, $test) = @_;

   die "Test name is needed in Bench::Test::Base->get_result\n" unless $test;

   my $basefile = "$test.base";
   my $wd = $self->{WORKDIR};

   warn "Error trying to access $wd\n" unless (-d $wd);

   chdir $self->{WORKDIR};

   my $output;
   if (-r $basefile) {
      local $/ = undef;
      open BASE, "< $basefile" or die "Error trying to open $basefile\n";
      $output = <BASE>;
      close BASE               or die "Error trying to close $basefile\n";
   }
   else {
      warn "Base file $basefile not found!\n";
   }

   chdir $self->{CURRENTDIR};

   return $output;
}
